import { getApisData, getNestApiData } from '@/services/cpasRequest';

export async function updateInvAgeConfig(dbname: string, paramsData: any[]) {
  const postData = {
    apis: [
      {
        name: 'sqlApi.update',
        params: {
          name: `[${dbname}]..INV_Product_aging_setter`,
          rows: paramsData,
        },
      },
    ],
    reload: true,
    params: {},
  };
  const resApis = await getApisData(postData);
  const resUpdate = resApis.data['sqlApi.update'];
  if (resApis.ok && resUpdate.ok) {
    return Promise.resolve({
      data: 'INV_Product_aging_setter, 更改信息成功！',
      success: true,
    });
  }
  return Promise.resolve({
    data: resApis.data,
    success: false,
  });
}

export async function getInvAgeConfig(params: any) {
  const res = await getNestApiData('/inventoryAge/config', 'post', params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.reject({
    data: res.data,
    success: false,
  });
}

export async function getInvAgeColumns(params: any) {
  const res = await getNestApiData('/inventoryAge/columns', 'post', params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.reject({
    data: res.data,
    success: false,
  });
}
